<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>到货验收---加电检验</title>

    <!--公用样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/comment.css"/>
    <!--页面样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/style.css"/>
    <!--Layui-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/layui/css/layui.css" media="all"/>
    <!--extended-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/extended.css"/>
    <!--公用样式JS-->
    <script type="text/javascript" src="${re.contextPath}/plugin/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/comment.js"></script>
    <script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/jquery.boot.js"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/tools/tool.js"></script>
    <script type="text/javascript" src="${re.contextPath}/pageoffice.js" id="po_js_main"></script>
</head>
<style type="text/css">
    .main {
        float: left;
        margin-left: 8px;
    }
</style>

<body>
<!--容器-->
<div>
    <div class="downModule whitebg">
        <ul class="mt30 mb30">
            <li>
                <div class="clearfix">
                    <div class="downModuleTip clearfix fl">
                        <img src="${re.contextPath}/plugin/common/images/15@2x.png" alt="" class="fl">
                        <span class="fl ml10 mt10 milefile" data-filetype="041">设备加电检测记录表</span>
                        <input type="hidden" name="id" id="id" value="${filedto.projectId}">
                        <input type="hidden" name="spmId" id="spmId" value="${filedto.spmId}">
                        <input type="hidden" name="fbCode" id="fbCode" value="${contract.code}">
                        <input type="hidden" name="fileId" id="fileId" value="${filedto.id}">
                        <input type="hidden" name="fbId" id="fbId" value="${contract.id}">
                        <input type="hidden" name="stageId" id="stageId" value="${filedto.stageId}">
                    </div>
                    <div class="downModuleBtn clearfix fr">
                        <label>
                            <img src="${re.contextPath}/plugin/common/images/18@2x.png" alt=""
                                 class="fl ">
                            <button type="button" style="display: none;" lay-data="{type: '041',value:'21'}"
                                    class="img-upload whitebutton ft12 blue">点击上传
                            </button>
                        </label>
                        <img src="${re.contextPath}/plugin/common/images/57@2x.png" alt="" class="fl" onclick="addForm(this)">
                        <img src="${re.contextPath}/plugin/common/images/19@2x.png" alt="" class="fl"
                             onclick="clickDelete(this)">
                    </div>
                </div>
                <ul class="clearfix">
                    <#list list_file as vo>
                        <li class="clearfix">
                            <input type="checkbox" class="fl" value="${vo.id}" title="jlzb">
                            <span class="fl ml10">${vo.fileName}</span>
                            <@shiro.hasPermission name="file:thrstamp">
                                <button type="button" class="fr ml20 mt15 bgnone filelist-btn" onclick="jfsqclick(this)">监发三签</button>
                            </@shiro.hasPermission>
                            <#--                            <@shiro.hasPermission name="file:upseal">-->
                            <#--                                    <button type="button" class="fr mt15 bgnone ml20 upseal tabsealup0">上传签章</button>-->
                            <#--                            </@shiro.hasPermission>-->
                            <@shiro.hasPermission name="file:export">
                                <button type="button" class="fr ml20 mt15 bgnone filelist-btn" onclick="exportFile(this)">导出</button>
                            </@shiro.hasPermission>
                            <@shiro.hasPermission name="file:view">
                                <button type="button" class="fr mt15 bgnone ml20 filelist-btn btn_vew" onclick="viewFile(this)">查看</button>
                            </@shiro.hasPermission>
                        </li>
                    </#list>
                </ul>
            </li>
        </ul>
    </div>
</div>
<script type="text/javascript" src="${re.contextPath}/plugin/system/supervisor/guide.js"></script>
<script>
    var layer, form, laydate, upload, uploadListIns, element, tableIns, table;
    $(function () {
        layui.use(['form', 'laydate', 'layer', 'upload', 'element', 'table'], function () {
            laydate = layui.laydate;
            form = layui.form;
            upload = layui.upload;
            element = layui.element;
            table = layui.table;
            // 加电检验上传
            <#--var datajson = {-->
            <#--    "id": "${filedto.projectId}", // 项目id-->
            <#--    "parentId": "${filedto.id}", // -->
            <#--    "fbId": "${contract.id}", // 分包表id-->
            <#--    "type": "041",-->
            <#--    "uploadType": "21"-->
            <#--}-->

            var  datajson = {
                "id": "${filedto.projectId}", //项目id
                "spmId": "${filedto.spmId}", //里程id
                "type": '041', //文件类型
                "fs_status": '21', //传的时候 对应的状态p'r
                "stageId": "${filedto.stageId}", // 阶段id
                "fbId": "${contract.id}",
                "parentId": "${filedto.id}"
            }

            var url = '/supervisor/projectManager/addFile';
            upload.render({
                elem: ".img-upload",
                url: url,
                multiple: true,
                accept: 'file',
                auto: true,
                data: datajson,
                before: function (obj) {
                    var item = this.item;
                    // 获取文件id
                    // datajson.parentId = $(item).parent().find("[type=checkbox]").attr("value");
                },
                done: function (res, index, upload) {
                    var flag = res.flag;
                    if (flag) {
                        var url = res.data;
                        // console.log("看看url：",url)
                        window.location.reload();
                    } else {
                        layer.msg("文件上传失败", {icon: 2})
                    }
                },
                error: function (index, upload) {
                    layer.msg("文件上传失败", {icon: 2})
                }
            });

        });
    });

    function clickDelete(object) {
        var checkbox = $(object).parent().parent().next().find("input:checked");
        if (checkbox.length == 0) {
            layer.msg("请选择文件", {icon: 2});
            return;
        }
        var ids = [];
        checkbox.each(function (i, v) {
            var _a = $(v).attr("value");
            ids.push(_a);
        });
        var ids = ids.join(',');
        layerAjax("deleteFile",{"ids": ids},'',function (data) {
            checkbox.each(function (i, v) {
                $(v).parent().remove();
            });
            layer.msg("删除成功！");
        })

    }
    function exportFile(object) {
        var input = $(object).parent().find("input");
        var id = $(input).attr("value");
        window.open("/supervisor/projectManager/exportFile?id=" + id);
    }
    function addForm(object) {
        var id= $("#id").val();// 项目id
        var spmId= $("#spmId").val();// spmId
        var stageId= $("#stageId").val();// stageId
        var fileId = $("#fileId").val();// 文件id
        var fbId = $("#fbId").val();// 文件id
        var type="041";// 文件类型
        var fbCode=$("#fbCode").val();//分包编号
        var title = "";
        var w,h;
        if (!w) {
            w = ($(window).width())-300;
        }
        if (!h) {
            h = ($(window).height() - 80);
        }
        var url = "/supervisor/projectManager/addForm?type=" + type + "&id=" + id + "&stageId=" + stageId + "&spmId=" + spmId + "&fbCode=" + fbCode + "&fileId=" + fileId+ "&fbId=" + fbId;
        layer.open({
            id: 'form-add',
            type: 2,
            area: [w + 'px', h + 'px'],
            fix: false,
            maxmin: true,
            shadeClose: false,
            shade: 0.4,
            title: title,
            content: url,
            success: function(layero){
                layero.find('.layui-layer-min').remove();
            },
            end: function () {
                reload();//刷新列表页面
            }
        });
    }
    // form 关闭之后回调
    function reload() {
        window.location.reload()
    }

    function viewFile(a) {
        var that = $(a);
        var _fid = that.parent().find('input[type=checkbox]').attr('value');
        if (_fid) {
            POBrowser.openWindowModeless('/sys/office/openword?ft=3&fid=' + _fid, 'width=1200px;height=800px;', '{}')
        } else {
            layer.msg('未获取到文件ID。', {icon: 2});
        }
    }

    function jfsqclick(object) {
        // 监发三签
        var that = $(object);
        // 文件id
        var fileId = that.parent().find('input[type=checkbox]').attr('value');
        // 项目id
        var  projectId ='${filedto.projectId}';
        var  spanfile=that.parent().find("span").html()
        var fileName=spanfile.substring(0,spanfile.indexOf('.'));
        var jsonsp={
            type:"004",//监发三签
            projectId:projectId,
            fileId:fileId,
            fileName:fileName
        }
        var title = "";
        var url = "/supervisor/lcManager/lcselectJsr?type=004&projectId=" + projectId + "&fileId=" + fileId + "&fileName=" + fileName ;
        layer.open({
            id: 'form-add',
            type: 2,
            area: ['600px', '400px'],
            fix: false,
            maxmin: true,
            shadeClose: false,
            shade: 0.4,
            title: title,
            content: url
        });

    }

</script>
</body>

</html>
